package com.shencai.demo;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * <p>
 * 代码生成器演示
 * </p>
 */
public class MpGenerator {

    /**
     * <p>
     * MySQL 生成演示
     * </p>
     */
    public static void main(String[] args) {
        g3();
    }

    public static void g3() {
        String dbUrl = "jdbc:mysql://192.168.252.132:3209/shencai-saas-demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&generateSimpleParameterMetadata=true";
        String dbUser = "dev_train";
        String dbPsw = "dev@2022";
        // 代码生成器
        FastAutoGenerator.create(dbUrl, dbUser, dbPsw)
                .globalConfig(builder -> {
                    builder.author("yxl") // 设置作者
                            .outputDir("D://mybatis"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.shencai") // 设置父包名
                            .moduleName("system")// 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D://mybatis")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("system_base_user")
                            // 设置需要生成的表名
                            .addTablePrefix("system")// 设置过滤表前缀
                            .entityBuilder().naming(NamingStrategy.underline_to_camel).columnNaming(NamingStrategy.no_change)
                            .mapperBuilder().superClass(BaseMapper.class)
                            .serviceBuilder().superServiceClass(IService.class).superServiceImplClass(ServiceImpl.class);
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }


}